package net.butfly.bus.config.bean;

import net.butfly.bus.config.bean.invoker.InvokerBean;

public class NodeBean extends ConfigBean {
	private static final long serialVersionUID = -2487543804206959704L;
	private String id;
	private InvokerBean invoker;
	private String[] tx;

	public NodeBean(String id, String tx, InvokerBean invoker) {
		this.id = id;
		this.tx = null == tx ? new String[0] : tx.split(",");
		this.invoker = invoker;
	}

	public String getId() {
		return id;
	}

	public InvokerBean getInvoker() {
		return invoker;
	}

	public boolean matchTx(String code) {
		for (String x : this.tx) {
			if (x.equals("*"))
				return true;
			if (x.equalsIgnoreCase(code))
				return true;
			if (x.endsWith("*") && code.startsWith(x.substring(0, x.indexOf("*"))))
				return true;
		}
		return false;
	}
}
